package net.openadventure;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;

public class JQTester {

    /**
     * @param args
     */ 
    public static void main(String[] args) {
        System.out.println("Java Quest Tester started...");
        System.out.println("YeeHaw!");
        boolean fullScreen = false; // Determines if the game will run full screen

        // Create a container to hold the game
        JFrame testFrame = new JFrame("Java Quest Tester");
        // Add ESC listener to quit...
        testFrame.addKeyListener( new KeyAdapter() {
          public void keyPressed( KeyEvent e ) {
            if( e.getKeyCode() == KeyEvent.VK_ESCAPE )
              System.exit(0);
            }
        });

        // Create the background canvas
        BackgroundCanvas background = new BackgroundCanvas(640, 480);

        // Create the foreground canvas
        ForegroundCanvas foreground = new ForegroundCanvas(640, 480);

        // Add the game to the container
        testFrame.setContentPane(background.getJPanel());
        testFrame.setGlassPane(foreground.getJPanel());

        // Show the foreground.  This must be done after it has been set as the GlassPane.
        foreground.getJPanel().setVisible(true);

        // Connect the canvases to an Engine
        Engine engine = new Engine(foreground, background, 60);

        // Start the Engine
        engine.start();

        // Setup the remaining container settings.
        //testFrame.setResizable(false);
        testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        if (fullScreen) {
            GraphicsDevice gd;
            try {
                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                gd = ge.getDefaultScreenDevice();

                testFrame.setUndecorated(true);
                gd.setFullScreenWindow(testFrame);

            } finally {

            }
        } else {
            // Finalize the container
            testFrame.pack();
            testFrame.setVisible(true);
        }
    }
}
